package com.lizardmind.haofudoctor.ui.studio.diagnose

import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.linxiao.framework.activity.BaseActivity
import com.linxiao.framework.util.ke
import com.linxiao.framework.widget.Section.SectionDecoration
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.manager.postApi
import com.lizardmind.haofudoctor.other.BaseDocumentsBean
import com.lizardmind.haofudoctor.other.DiagnoseManageBean
import com.lizardmind.haofudoctor.other.DoctorInfo
import com.lizardmind.haofudoctor.other.Request
import com.lizardmind.haofudoctor.ui.diagnosis.diagnose.SendDiagnoseAdapter
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_studio_diagnose.*
import kotlinx.android.synthetic.main.include_title_text.*
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast

/**
 *
 * Created by Extends on 2017/11/24 11:33
 */
class DiagnoseStudioActivity:BaseActivity() {
    private val apt by lazy { SendDiagnoseAdapter(this, arrayListOf<BaseDocumentsBean>(),false) }
    override fun onCreatRootView(): View? {
        setContentView(R.layout.activity_studio_diagnose)
        return null
    }

    override fun onInitView(savedInstanceState: Bundle?) {
        //初始化title
        imgLeft.setImageResource(R.mipmap.back)
        imgLeft.onClick { finish() }
        titleText.text = "问诊单"

        sd_rv.apply {
            isNestedScrollingEnabled = false
            layoutManager = LinearLayoutManager(context)
            adapter = apt
            addItemDecoration(SectionDecoration(1, apt,false,0.3f))
        }
        asd_cl0.onClick { startActivity<HistoryDiagnoseActivity>("type" to 0) }
        asd_cl1.onClick { startActivity<HistoryDiagnoseActivity>("type" to 1) }
//        apt.onSend = { position, data ->
//            toast(data)
//            ke("------------")
//        }

        observe {
            postApi<Request<DiagnoseManageBean>>(hashMapOf(
                    "action" to "manage_diagnose",
                    "token" to DoctorInfo.token
            ), Consumer {
                it.dispose {
                    apt.addAllAndClear(it.list)
                    asd_price.text = getString(R.string.price,it.price)
                    asd_send.text = it.send
                    asd_receive.text = it.receive
                }
            })
        }
    }
}